// 暂时不使用， 难点：无法实时将值传入父组件并更新

import React,{ Component } from 'react';
import './index.css';
import {Modal} from 'antd';
import SelectFileForm from '../Modal/select-file-form';
import { connect } from 'react-redux';
import {getCurvesIntoDao} from '../../redux/actions';

class ShowHeader extends Component{
  state = {
    visible: '0'
  }

  openFileShow = () => {    // 添加数据文件 弹框显示
    this.setState({
      visible: '1'
    });
  };
  handleOpenFile = async() => {    // 添加数据文件 响应函数 
    this.setState({ visible: '0'});
    const data_file = this.formRef.current.getFieldValue('data_file');
    // console.log("file1",data_file);
    // this.file = data_file;

    this.props.getCurvesIntoDao(data_file.curves);
    console.log("数据文件名称：",data_file.curves);
  }; 
  handleCancel = () => {    // 对话框取消按钮

    this.setState({
      visible: '0'
    });
  };

  // componentDidMount() {
  //   this.props.setFile(this.file);  // 调用父组件传递的函数，目的是将 参数以实参的形式传递给父组件  
  // }


  render(){
    const {visible} = this.state;
    return (
      <div className="show-header-wrapper" >
        <i className="iconfont icon" onClick={this.openFileShow}>&#xe715;</i>
        <i className="iconfont icon">&#xe606;</i>
        <Modal
          title="选择数据文件"
          visible={visible === '1'}
          onOk={this.handleOpenFile}
          onCancel={this.handleCancel}
          okText="确定"
          cancelText="取消"
          destroyOnClose={true}
        >
          <SelectFileForm setForm = {(formRef) => {this.formRef = formRef}}/> 
        </Modal>
      </div>
    )
  }
}

export default connect(
  state => ({}),// 用来显示
  {getCurvesIntoDao}  // 用来更新
)(ShowHeader);